package aigle.idm.diagraph.tp4.diagram_default_root.part;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.tooling.runtime.structure.DiagramStructure;

import aigle.idm.diagraph.tp4.Infrastructure;
import aigle.idm.diagraph.tp4.Tp4Package;

/**
 * This registry is used to determine which type of visual object should be
 * created for the corresponding Diagram, Node, ChildNode or Link represented
 * by a domain model object.
 * 
 * @generated
 */
public class Tp4VisualIDRegistry {

	/**
	 * @generated
	 */
	private static final String DEBUG_KEY = "aigle.idm.diagraph.tp4.diagram_default_root/debug/visualID"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static int getVisualID(View view) {
		if (view instanceof Diagram) {
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.MODEL_ID
					.equals(view.getType())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		return aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
				.getVisualID(view.getType());
	}

	/**
	 * @generated
	 */
	public static String getModelID(View view) {
		View diagram = view.getDiagram();
		while (view != diagram) {
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
			if (annotation != null) {
				return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
			}
			view = (View) view.eContainer();
		}
		return diagram != null ? diagram.getType() : null;
	}

	/**
	 * @generated
	 */
	public static int getVisualID(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			if (Boolean.TRUE.toString().equalsIgnoreCase(
					Platform.getDebugOption(DEBUG_KEY))) {
				aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4DiagramEditorPlugin
						.getInstance().logError(
								"Unable to parse view type as a visualID number: "
										+ type);
			}
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static String getType(int visualID) {
		return Integer.toString(visualID);
	}

	/**
	 * @generated
	 */
	public static int getDiagramVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (Tp4Package.eINSTANCE.getInfrastructure().isSuperTypeOf(
				domainElement.eClass())
				&& isDiagram((Infrastructure) domainElement)) {
			return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static int getNodeVisualID(View containerView, EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		String containerModelID = aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
				.getModelID(containerView);
		if (!aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.MODEL_ID
				.equals(containerModelID)) {
			return -1;
		}
		int containerVisualID;
		if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.MODEL_ID
				.equals(containerModelID)) {
			containerVisualID = aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		switch (containerVisualID) {
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.VISUAL_ID:
			if (Tp4Package.eINSTANCE.getCalculateur().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurEditPart.VISUAL_ID;
			}
			if (Tp4Package.eINSTANCE.getPeripherique().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.PeripheriqueEditPart.VISUAL_ID;
			}
			if (Tp4Package.eINSTANCE.getLocalisation().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.LocalisationEditPart.VISUAL_ID;
			}
			if (Tp4Package.eINSTANCE.getVueDocumentation().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationEditPart.VISUAL_ID;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurProcesseursEditPart.VISUAL_ID:
			if (Tp4Package.eINSTANCE.getProcesseur().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.ProcesseurEditPart.VISUAL_ID;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationFamillesEditPart.VISUAL_ID:
			if (Tp4Package.eINSTANCE.getFamille().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleEditPart.VISUAL_ID;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationNomenclaturesEditPart.VISUAL_ID:
			if (Tp4Package.eINSTANCE.getNomenclature().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.NomenclatureEditPart.VISUAL_ID;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleDocusEditPart.VISUAL_ID:
			if (Tp4Package.eINSTANCE.getDocumentation().isSuperTypeOf(
					domainElement.eClass())) {
				return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.DocumentationEditPart.VISUAL_ID;
			}
			break;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
		String containerModelID = aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
				.getModelID(containerView);
		if (!aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.MODEL_ID
				.equals(containerModelID)) {
			return false;
		}
		int containerVisualID;
		if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.MODEL_ID
				.equals(containerModelID)) {
			containerVisualID = aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.VISUAL_ID;
			} else {
				return false;
			}
		}
		switch (containerVisualID) {
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.PeripheriqueEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.LocalisationEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurNomEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurProcesseursEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.PeripheriqueEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.PeripheriqueNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.PeripheriqueNatureEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.LocalisationEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.LocalisationNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationFamillesEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationNomenclaturesEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.ProcesseurEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.ProcesseurNomEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.ProcesseurCadenceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleNomEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleDocusEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.DocumentationEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.DocumentationDescriptionEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.NomenclatureEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.NomenclatureNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurProcesseursEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.ProcesseurEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationFamillesEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationNomenclaturesEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.NomenclatureEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleDocusEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.DocumentationEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InterfaceEditPart.VISUAL_ID:
			if (aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InterfaceCadenceEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static int getLinkWithClassVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (Tp4Package.eINSTANCE.getInterface().isSuperTypeOf(
				domainElement.eClass())) {
			return aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InterfaceEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * User can change implementation of this method to handle some specific
	 * situations not covered by default logic.
	 * 
	 * @generated
	 */
	private static boolean isDiagram(Infrastructure element) {
		return true;
	}

	/**
	 * @generated
	 */
	public static boolean checkNodeVisualID(View containerView,
			EObject domainElement, int candidate) {
		if (candidate == -1) {
			//unrecognized id is always bad
			return false;
		}
		int basic = getNodeVisualID(containerView, domainElement);
		return basic == candidate;
	}

	/**
	 * @generated
	 */
	public static boolean isCompartmentVisualID(int visualID) {
		switch (visualID) {
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.CalculateurProcesseursEditPart.VISUAL_ID:
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationFamillesEditPart.VISUAL_ID:
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.VueDocumentationNomenclaturesEditPart.VISUAL_ID:
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.FamilleDocusEditPart.VISUAL_ID:
			return true;
		default:
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static boolean isSemanticLeafVisualID(int visualID) {
		switch (visualID) {
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.InfrastructureEditPart.VISUAL_ID:
			return false;
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.PeripheriqueEditPart.VISUAL_ID:
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.LocalisationEditPart.VISUAL_ID:
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.ProcesseurEditPart.VISUAL_ID:
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.DocumentationEditPart.VISUAL_ID:
		case aigle.idm.diagraph.tp4.diagram_default_root.edit.parts.NomenclatureEditPart.VISUAL_ID:
			return true;
		default:
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static final DiagramStructure TYPED_INSTANCE = new DiagramStructure() {
		/**
		 * @generated
		 */

		public int getVisualID(View view) {
			return aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.getVisualID(view);
		}

		/**
		 * @generated
		 */

		public String getModelID(View view) {
			return aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.getModelID(view);
		}

		/**
		 * @generated
		 */

		public int getNodeVisualID(View containerView, EObject domainElement) {
			return aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.getNodeVisualID(containerView, domainElement);
		}

		/**
		 * @generated
		 */

		public boolean checkNodeVisualID(View containerView,
				EObject domainElement, int candidate) {
			return aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.checkNodeVisualID(containerView, domainElement, candidate);
		}

		/**
		 * @generated
		 */

		public boolean isCompartmentVisualID(int visualID) {
			return aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.isCompartmentVisualID(visualID);
		}

		/**
		 * @generated
		 */

		public boolean isSemanticLeafVisualID(int visualID) {
			return aigle.idm.diagraph.tp4.diagram_default_root.part.Tp4VisualIDRegistry
					.isSemanticLeafVisualID(visualID);
		}
	};

}
